//
//  TrainingDetailTotalCell.swift
//  DaRings
//
//  Created by 尹琼 on 2022/11/18.
//

import UIKit
import MYModule

open class TrainingDetailworkoutsRecordCell: TableViewCell {
    
   
    open var totalData: TrainingDetailWorkoutsRecordModel? {
        
        didSet {
            
            guard let totalData = totalData else {
                return
            }
            
            
            self.titleLabel.attributedText = totalData.returnTitleAttributeString()
            self.subtitleLabel.attributedText = totalData.returnSubtitleAttributeString()
        
            progressView.snp.updateConstraints { make in
                make.height.equalTo(8)
            }
            progressView.progress = totalData.progress
            if totalData.trainingModel?.goalType == 0 {
                progressView.highProgress = 0.5
            } else {
                progressView.highProgress = 0.0
            }
        
            if self.totalData?.trainingModel?.goalType == 255 {
                progressView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
            }
            
    
            
        }
        
    }
    
    public let progressView = TrainingProgressView()
    
    public let titleLabel = Label()
    public let subtitleLabel = Label()
    
   
    
    open override func makeUI() {
        super.makeUI()
        
        
        contentView.addSubview(titleLabel)
        contentView.addSubview(subtitleLabel)
        contentView.addSubview(progressView)
        
        titleLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(20)
            make.centerX.equalToSuperview()
           
        }
        
        subtitleLabel.snp.makeConstraints { make in
            make.top.equalTo(titleLabel.snp.bottom).offset(6)
            make.centerX.equalToSuperview()
            
        }
        
        progressView.snp.makeConstraints { make in
            make.top.equalTo(subtitleLabel.snp.bottom).offset(12)
            make.left.equalToSuperview().offset(92)
            make.right.equalToSuperview().offset(-92)
            make.height.equalTo(8)
            make.bottom.equalToSuperview()
        }
        
        progressView.progressView.backgroundColor = UIColor.Training.theme
        progressView.highProgressView.backgroundColor = UIColor.Training.theme.withAlphaComponent(0.6)
    }
    
}

